package com.didispace.web;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.*;

import java.util.Random;


@RestController
public class HelloController {


    @Autowired
    private DiscoveryClient client;


    @RequestMapping("/hello")
    public String hello() {
        int sleepTime = new Random().nextInt(2400) + 100;
        try {
            Thread.sleep(sleepTime);
        } catch (InterruptedException e) {

        }
        ServiceInstance instance = client.getLocalServiceInstance();
        System.out.println("/hello, host:" + instance.getHost() + ", service_id:" + instance.getServiceId());
        return "Another Hello";
    }

    @RequestMapping("/vnshu")
    public String vnshu(@RequestParam("blog") String blog) {
        return "vnshu\t" + blog;
    }

}